package com.chenenjun.db;

import java.sql.Connection;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3P0DB {
	
	public static Connection getConnection(){
		Connection conn = null;
		try {
			/*
			 * 这里使用的是c3p0连接池，注意它的配置文件是必须要叫做c3p0-config.xml的，否则不好使
			 */
			ComboPooledDataSource ds = new ComboPooledDataSource("mysql");
			conn = ds.getConnection();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void main(String[] args) {
		if(C3P0DB.getConnection() != null){
			System.out.println("数据库连接成功！");
		} else {
			System.out.println("数据库连接失败！");
		}
	}
}
